﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CP.Utility;

namespace GPM
{
    public partial class FrmUtility : Form
    {
        public FrmUtility()
        {
            InitializeComponent();
        }

        private void btnMD5_Click(object sender, EventArgs e)
        {
            this.txtAfterEncrypt.Text = EncryptHelper.MD5(this.txtBeforeEncrypt.Text);
        }

        private void btnEncryptDES_Click(object sender, EventArgs e)
        {
            if (this.txtEncryptKey.Text.Length < 8)
            {
                ExMessageBox.Show("密钥长度不能少于8位");
                return;
            }
            this.txtAfterEncrypt.Text = EncryptHelper.EncryptDES(this.txtBeforeEncrypt.Text,this.txtEncryptKey.Text);
        }

        private void btnDescryptDES_Click(object sender, EventArgs e)
        {
            if (this.txtEncryptKey.Text.Length < 8)
            {
                ExMessageBox.Show("密钥长度不能少于8位");
                return;
            }
            this.txtBeforeEncrypt.Text = EncryptHelper.DecryptDES(this.txtAfterEncrypt.Text, this.txtEncryptKey.Text);
        }

        private void btnDesEncryptWithIV_Click(object sender, EventArgs e)
        {
            if (this.txtEncryptKey.Text.Length < 8)
            {
                ExMessageBox.Show("密钥长度不能少于8位");
                return;
            }
            if (this.txtEncryptIV.Text.Length < 8)
            {
                ExMessageBox.Show("加密向量长度不能少于8位");
                return;
            }
            this.txtAfterEncrypt.Text = EncryptHelper.DESEncrypt(this.txtBeforeEncrypt.Text, this.txtEncryptKey.Text,this.txtEncryptIV.Text);
        }

        private void btnDesDescryptWithIV_Click(object sender, EventArgs e)
        {
            if (this.txtEncryptKey.Text.Length < 8)
            {
                ExMessageBox.Show("密钥长度不能少于8位");
                return;
            }
            if (this.txtEncryptIV.Text.Length < 8)
            {
                ExMessageBox.Show("加密向量长度不能少于8位");
                return;
            }
            this.txtBeforeEncrypt.Text = EncryptHelper.DESDecrypt(this.txtAfterEncrypt.Text, this.txtEncryptKey.Text,this.txtEncryptIV.Text);
        }
    }
}
